package com.futures.questionbank.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.classic.adapter.CommonRecyclerAdapter;
import com.futures.questionbank.Constants.Constants;
import com.futures.questionbank.R;
import com.futures.questionbank.adapter.HomeJobAdapter;
import com.futures.questionbank.base.BaseFragment;
import com.futures.questionbank.bean.HangQinBean;
import com.futures.questionbank.http.CallBack;
import com.futures.questionbank.http.HttpClient;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

public class HangqingFragment2 extends BaseFragment {

    @BindView(R.id.rl_choice)
    RecyclerView rlJob2;

    @Override
    protected int getLayoutResource() {
        return R.layout.hang_fragment;
    }

    public static HangqingFragment2 newInstance(int i) {
        Bundle args = new Bundle();
        args.putInt("id", i);
        HangqingFragment2 fragment = new HangqingFragment2();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    private void initView() {
        int i = getArguments().getInt("id");
        rlJob2.setLayoutManager(new LinearLayoutManager(getActivity()));
        rlJob2.setItemAnimator(new DefaultItemAnimator());
        HomeJobAdapter homeJobAdapter = new HomeJobAdapter(getActivity());
        rlJob2.setAdapter(homeJobAdapter);

        String url;
        Map<String, Object> params = new HashMap<>();

        if (i== 0){
             url = Constants.HUOBIPRO;
        }else if (i==1){
             url = Constants.OKEX;
        }else if (i== 2){
             url = Constants.BITHUMB;
        }else if (i==3){
             url = Constants.BITTREX;
        }else if (i==4){
             url = Constants.BITSTAMP;
        }else {
             url = Constants.BITFINEX;
        }


       HttpClient.get(getActivity(),url, params, new CallBack<List<HangQinBean>>() {
            @Override
            public void onSuccess(List<HangQinBean> jobListBeans) {
                homeJobAdapter.replaceAll(jobListBeans, true);
            }
        });
        //得到职位
        //   getJobList();

        homeJobAdapter.setOnItemClickListener(new CommonRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {
              //  startActivity(new Intent(getActivity(), HomeJobActivity.class).putExtra("id",homeJobAdapter.getItem(i).getPartJobId()));
            }
        });
    }
}
